/**
 * 
 */
package com.haoho.commons.dao;

import java.io.Serializable;

/**
 * @param T domain object.
 * @param PK primary key of domain object.
 * @author hthao
 * 
 */
public interface GenericDao<T, PK extends Serializable> {

	/**
	 * Gets an object by ID.
	 * @param id is a primary key
	 * @return domain object 
	 * @throws Exception if have any error
	 */
	T findById (PK id) throws Exception;
	
	/**
	 * Update a record.
	 * @param entity will be updated
	 * @throws Exception if have any error
	 */
	void update(T entity) throws Exception;
	
	/**
	 * Add a record to table.
	 * @param entity will be added.
	 * @throws Exception if have any error.
	 */
	void create(T entity) throws Exception;
	
	/**
	 * Deleted a record in table by primary key.
	 * @param id is primary key of domain object.
	 * @throws Exception if have any error
	 */
	void delete(PK id) throws Exception;
	
	/**
	 * Run SQL script files base on path of file.
	 * @param path is a path to file or directory located sql script.
	 * @throws Exception if have any error
	 */
	void runSqlScriptFiles(String path) throws Exception;
}
